package com.example.liyuehui.myapplication;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class TestRecyclerviewAdapter extends RecyclerView.Adapter<TestRecyclerviewAdapter.VH> {

	Context context ;

	public TestRecyclerviewAdapter(Context context) {
		this.context = context;
	}

	@Override
	public VH onCreateViewHolder(ViewGroup parent, int viewType) {
		View view = LayoutInflater.from(context).inflate(R.layout.item_view,parent,false);
		return new VH(view);
	}

	@Override
	public void onBindViewHolder(VH holder, int position) {
		((NestedPagerAdapter)holder.viewPager.getAdapter()).setCurrentRecyclerViewPosition(position);
	}

	@Override
	public int getItemCount() {
		return 2;
	}

	class VH extends RecyclerView.ViewHolder{
		ViewPager viewPager;


		public VH(View itemView) {
			super(itemView);
			viewPager = itemView.findViewById(R.id.viewpager);
			viewPager.setAdapter(new NestedPagerAdapter());
		}
	}
}
